/*
 * Vectrics 
 * Created on Feb 1, 2004
 *
 */
package org.vectrics.common.graphics;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;


/**
 * @author mmoore

 */
abstract public class Graphic {
	private Graphics2D g2 = null;
	private Color backgroundColor = Color.BLUE;
	
    public Graphic() {
        
    }
	
	
	abstract public int getWidth();
	abstract public int getHeight();
	
	public Color getBackgroundColor() {
	    return(backgroundColor);
	}
	
	public void setBackgroundColor(Color color) {
	    this.backgroundColor = color;
	}
	
	abstract protected void doFill(Graphics2D graphics2d);
	
	
	public final BufferedImage fill() {
	    int width = this.getWidth();
	    int height = this.getHeight();
		BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
		Graphics2D g2 = image.createGraphics();
		
		if (getBackgroundColor() != null) {
			g2.setColor(getBackgroundColor());
			g2.fillRect(0, 0, this.getWidth(), this.getHeight());
		}
		
		doFill(g2);
		
		g2.dispose();
		return(image);
	}
	
}
